package com.ptszyxx.popose.module.main.mine.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.RxTextTool;
import com.ptszyxx.popose.databinding.ItemMineVipBinding;
import com.ysg.http.data.entity.mine.VipEntity;
import com.ptszyxx.popose.module.main.mine.vm.MineVipVM;

public class MineVipAdapter extends BaseQuickAdapter<VipEntity, BaseDataBindingHolder<ItemMineVipBinding>> {

    private MineVipVM viewModel;
    private Presenter mPresenter = new Presenter();
    private int currentPosition = 0;

    public MineVipAdapter(MineVipVM viewModel) {
        super(R.layout.item_mine_vip);
        this.viewModel = viewModel;
    }

    public void setPosition(int position) {
        this.currentPosition = position;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemMineVipBinding> holder, VipEntity item) {
        ItemMineVipBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.setPresenter(mPresenter);
            binding.setPosition(holder.getBindingAdapterPosition());
            binding.executePendingBindings();

            String currency = getContext().getResources().getString(R.string.currency);//货币符号

            RxTextTool.getBuilder("", getContext())
                    .append(currency)
                    .setProportion(0.5f)
                    .append(item.getPriceDay() + "")
                    .append("/"+getContext().getString(R.string.day))
                    .setProportion(0.5f)
                    .into(binding.tvPrice);

            int position = holder.getBindingAdapterPosition();
            if (position == 0) {
                binding.tvTag.setBackgroundResource(R.mipmap.ic_vip_tag1);
            } else if (position == 1) {
                binding.tvTag.setBackgroundResource(R.mipmap.ic_vip_tag2);
            } else {
                binding.tvTag.setBackgroundResource(R.mipmap.ic_vip_tag3);
            }

            if (currentPosition == position) {
                binding.parent.setBackgroundResource(R.drawable.shape_vip_price_select);
            } else {
                binding.parent.setBackgroundResource(R.drawable.shape_vip_price_unselect);
            }

        }
    }

    public static class Presenter{
        public void onItemClick(MineVipVM viewModel, VipEntity entity, int position){
            viewModel.onItemClick(entity, position);
        }
    }







}
